﻿using System;
using System.ComponentModel;
using System.Windows.Input;

// TBD
// integrate binding for command
// 

namespace NormalGsearch
{
    class NormalGSearchViewModel : INotifyPropertyChanged
    {
        #region Events
        public event PropertyChangedEventHandler PropertyChanged;
        private event EventHandler RequestCloseEvent;
        private event EventHandler StartSearchRequested;
        #endregion

        #region Fields
        private string username;
        private string password; 
        private string statusMessage;
        private StartSearchCommand startSearchCommand;
        #endregion


        public NormalGSearchViewModel()
        {
            Initialize();
        }

        private void Initialize()
        {
            startSearchCommand = new StartSearchCommand(this);
        }

        public string StatusMessage
        {
            get
            {
                return statusMessage;
            }
            set
            {
                statusMessage = value;

                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("StatusMessage"));
                }
            }
        }

        public string Username
        {
            get
            {
                return username;
            }
            set
            {
                username = value;

                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("Username"));
                }
            }
        }

        public string Password
        {
            get
            {
                return password;
            }
            set
            {
                password = value;

                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("Password"));
                }
            }
        }

        public void OnStartSearchRequested()
        {
            if (StartSearchRequested != null)
            {
                StartSearchRequested(this, EventArgs.Empty);
            }
        }

        public event EventHandler OnRequestStartSearch
        {
            add { StartSearchRequested += value; }
            remove { StartSearchRequested -= value; }
        }

        public void RequestClose()
        {
            if (RequestCloseEvent != null)
            {
                RequestCloseEvent(this, EventArgs.Empty);
            }
        }

        public event EventHandler OnRequestClose
        {
            add { RequestCloseEvent += value; }
            remove { RequestCloseEvent -= value; }
        }

        public ICommand StartSearchCommand
        {
            get { return startSearchCommand; }
        }
    }
}
